package com.ywjt.platformbusiness.classify.adapter;

import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.classify.model.ShopListModel;
import com.ywjt.platformbusiness.market.commongoods.adapter.DynamicItemPictureAdapter;
import com.ywjt.platformbusiness.util.PictureUtils;

import java.util.ArrayList;
import java.util.List;

public class ShopListPAdapter extends BaseQuickAdapter<ShopListModel.ResultDTO.RecordsDTO, BaseViewHolder> {
    public ShopListPAdapter(@Nullable List<ShopListModel.ResultDTO.RecordsDTO> data) {
        super(R.layout.item_shop_list_p, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopListModel.ResultDTO.RecordsDTO item) {
        ImageView ivShopLogo=helper.getView(R.id.ivShopLogo);
        Glide.with(mContext).load(item.getShopLogo())
                .placeholder(R.mipmap.default_headlink)
                .apply(new RequestOptions().transform(new PictureUtils()))
                .into(ivShopLogo);
        helper.setText(R.id.tvShopName,item.getShopName());
        helper.setText(R.id.tvShopAddress,item.getAddress());
        helper.setText(R.id.tvDistance,item.getDistance());

        RecyclerView rcCommon=helper.getView(R.id.rcCommon);
        if (item.getShopPhoto()!=null){
            String p[]=item.getShopPhoto().split(",");
            List<String> ps=new ArrayList<>();
            if (p.length>0){
                for (int i=0;i<p.length;i++){
                    ps.add(p[i]);
                }
                DynamicItemPictureAdapter adapter=new DynamicItemPictureAdapter(ps);
                rcCommon.setAdapter(adapter);
                rcCommon.setLayoutManager(new GridLayoutManager(mContext,4,RecyclerView.VERTICAL,false));
            }
        }
    }
}